package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlForum entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlForum
 * @author MyEclipse Persistence Tools
 */

public class MdlForumDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlForumDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String TYPE = "type";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String ASSESSED = "assessed";
	public static final String ASSESSTIMESTART = "assesstimestart";
	public static final String ASSESSTIMEFINISH = "assesstimefinish";
	public static final String SCALE = "scale";
	public static final String MAXBYTES = "maxbytes";
	public static final String MAXATTACHMENTS = "maxattachments";
	public static final String FORCESUBSCRIBE = "forcesubscribe";
	public static final String TRACKINGTYPE = "trackingtype";
	public static final String RSSTYPE = "rsstype";
	public static final String RSSARTICLES = "rssarticles";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String WARNAFTER = "warnafter";
	public static final String BLOCKAFTER = "blockafter";
	public static final String BLOCKPERIOD = "blockperiod";
	public static final String COMPLETIONDISCUSSIONS = "completiondiscussions";
	public static final String COMPLETIONREPLIES = "completionreplies";
	public static final String COMPLETIONPOSTS = "completionposts";

	public void save(MdlForum transientInstance) {
		Transaction trx = getSession().beginTransaction();
		log.debug("saving MdlForum instance");
		try {
			getSession().save(transientInstance);
			trx.commit();
			log.debug("save successful");
			trx=null;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			trx=null;
			throw re;
		}
	}

	public void delete(MdlForum persistentInstance) {
		log.debug("deleting MdlForum instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlForum findById(java.lang.Long id) {
		log.debug("getting MdlForum instance with id: " + id);
		try {
			MdlForum instance = (MdlForum) getSession().get(
					"idv.loveloser.dao.MdlForum", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlForum instance) {
		log.debug("finding MdlForum instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlForum")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlForum instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlForum as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByAssessed(Object assessed) {
		return findByProperty(ASSESSED, assessed);
	}

	public List findByAssesstimestart(Object assesstimestart) {
		return findByProperty(ASSESSTIMESTART, assesstimestart);
	}

	public List findByAssesstimefinish(Object assesstimefinish) {
		return findByProperty(ASSESSTIMEFINISH, assesstimefinish);
	}

	public List findByScale(Object scale) {
		return findByProperty(SCALE, scale);
	}

	public List findByMaxbytes(Object maxbytes) {
		return findByProperty(MAXBYTES, maxbytes);
	}

	public List findByMaxattachments(Object maxattachments) {
		return findByProperty(MAXATTACHMENTS, maxattachments);
	}

	public List findByForcesubscribe(Object forcesubscribe) {
		return findByProperty(FORCESUBSCRIBE, forcesubscribe);
	}

	public List findByTrackingtype(Object trackingtype) {
		return findByProperty(TRACKINGTYPE, trackingtype);
	}

	public List findByRsstype(Object rsstype) {
		return findByProperty(RSSTYPE, rsstype);
	}

	public List findByRssarticles(Object rssarticles) {
		return findByProperty(RSSARTICLES, rssarticles);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByWarnafter(Object warnafter) {
		return findByProperty(WARNAFTER, warnafter);
	}

	public List findByBlockafter(Object blockafter) {
		return findByProperty(BLOCKAFTER, blockafter);
	}

	public List findByBlockperiod(Object blockperiod) {
		return findByProperty(BLOCKPERIOD, blockperiod);
	}

	public List findByCompletiondiscussions(Object completiondiscussions) {
		return findByProperty(COMPLETIONDISCUSSIONS, completiondiscussions);
	}

	public List findByCompletionreplies(Object completionreplies) {
		return findByProperty(COMPLETIONREPLIES, completionreplies);
	}

	public List findByCompletionposts(Object completionposts) {
		return findByProperty(COMPLETIONPOSTS, completionposts);
	}

	public List findAll() {
		log.debug("finding all MdlForum instances");
		try {
			String queryString = "from MdlForum";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlForum merge(MdlForum detachedInstance) {
		Transaction trx = getSession().beginTransaction();
		log.debug("merging MdlForum instance");
		try {
			MdlForum result = (MdlForum) getSession().merge(detachedInstance);
			trx.commit();
			log.debug("merge successful");
			trx=null;
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			trx=null;
			throw re;
		}
	}

	public void attachDirty(MdlForum instance) {
		log.debug("attaching dirty MdlForum instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlForum instance) {
		log.debug("attaching clean MdlForum instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}